package com.yun.algorithmproblem.leetcode;

public class Leetcode2116 {

    public static void main(String[] args) {
        Leetcode2116 obj = new Leetcode2116();
        System.out.println(obj.canBeValid("(((())(((())", "111111010111"));
    }

    public boolean canBeValid(String s, String locked) {
        int min = 0, max = 0;
        char[] sc = s.toCharArray();
        char[] lc = locked.toCharArray();
        for (int i = 0; i < sc.length; i++) {
            if (lc[i] == '0') {//这个位置的括号可以变化
                min--;
                if (min < 0) {
                    min = 1;
                }
                max++;
            } else {//这个位置括号不能变化
                if (sc[i] == '(') {
                    min++;
                    max++;
                } else {
                    max--;
                    if (max < 0) {
                        return false;
                    }
                    min--;
                    if (min < 0) {
                        min = 1;
                    }
                }
            }
        }
        return min == 0;
    }
}
